import { ApiResp } from "@/types/response";
import { apiClient, extractDataFromResponse } from ".";
import { OrderDetail } from "@/types/order";
import { Product } from "@/types/product";
import { OrderSummaryItem, TopNItem } from "@/types/chart";
import { AxiosResponse } from "axios";


export const merchantService = {
  getOrders: async () => {
    try {
      const response = await apiClient.get<ApiResp<OrderDetail[]>>("/merchant/orders", 
        // params: {
        //   page,
        //   pageSize,
        //   search,
        // }
      );
      return extractDataFromResponse<OrderDetail[]>(response);
    } catch (error) {
      console.error("Error:", error);
      return null;
    }
  },

  getProducts: async () => {
    try {
      const response = await apiClient.get<ApiResp<Product[]>>("/merchant/products", {
        // params: { page, pageSize },
      });
      return extractDataFromResponse<Product[]>(response);   
    } catch (error) {
      console.error("Error:", error);
      return null;
    }
  },


  shipOrder: async (orderId: number) => {
    try {
      const response = await apiClient.post<ApiResp<"success">>("/merchant/orders/ship", {orderId});
      return extractDataFromResponse<"success">(response);
    } catch (error) {
      console.error("Error:", error);
      return null;
    }
  },


  weeklyOrderSummary: async () => {
    try {
      const response = await apiClient.get<ApiResp<OrderSummaryItem[]>>("/merchant/ads/order-weekly-summary");
      return extractDataFromResponse<OrderSummaryItem[]>(response);
    } catch (error) {
      console.error("Error:", error);
      return null;
    }
  },

  top10Products: async () => {
    try {
      const response = await apiClient.get<ApiResp<TopNItem[]>>("/merchant/ads/top10-daily");
      return extractDataFromResponse<TopNItem[]>(response);
    } catch (error) {
      console.error("Error:", error);
      return null;
    }
  },


};